﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace QuanLyCongDoanVien.UserControls
{
    public partial class ucXoaToCongDoan : UserControl
    {
        public ucXoaToCongDoan()
        {
            InitializeComponent();
        }

        private void ucXoaToCongDoan_Load(object sender, EventArgs e)
        {
            try
            {
                cboToCongDoan.DataSource = ToCongDoanBUS.LayDanhSach();
                cboToCongDoan.DisplayMember = "TenToCongDoan";
                cboToCongDoan.SelectedIndex = -1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            if (cboToCongDoan.SelectedIndex == -1)
            {
                MessageBox.Show("Vui lòng chọn tổ công đoàn bạn muốn xóa");
                return;
            }
            string tenTDC = ((ToCongDoanDTO)cboToCongDoan.SelectedItem).TenToCongDoan;
            try
            {
                int iResult = ToCongDoanBUS.Xoa(tenTDC);
                if (iResult == 1)
                {
                    MessageBox.Show("Đã xóa tổ công đoàn");
                    cboToCongDoan.SelectedIndex = -1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            try
            {
                cboToCongDoan.DataSource = ToCongDoanBUS.LayDanhSach();
                cboToCongDoan.DisplayMember = "TenToCongDoan";
                cboToCongDoan.SelectedIndex = -1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
